home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWViews / FWContrH.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  25.5 KB  |  878 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWContrH.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifdef FW_BUILD_MAC
  11.  
  12. #include "FWFrameW.hpp"
  13.  
  14. #ifndef FWCONTRH_H
  15. #include "FWContrH.h"
  16. #endif
  17.  
  18. #ifndef FWSCLBAR_H
  19. #include "FWSclBar.h"
  20. #endif
  21.  
  22. #ifndef FWBUTTON_H
  23. #include "FWButton.h"
  24. #endif
  25.  
  26. #ifndef FWPOPUP_H
  27. #include "FWPopup.h"
  28. #endif
  29.  
  30. #ifndef FWFRAME_H
  31. #include "FWFrame.h"
  32. #endif
  33.  
  34. #ifndef FWWINDOW_H
  35. #include "FWWindow.h"
  36. #endif
  37.  
  38. #ifndef FWCONTXT_H
  39. #include "FWContxt.h"
  40. #endif
  41.  
  42. #ifndef FWITERS_H
  43. #include "FWIters.h"
  44. #endif
  45.  
  46. // ----- Foundation Layer -----
  47.  
  48. #ifndef FWNOTIFN_H
  49. #include "FWNotifn.h"
  50. #endif
  51.  
  52. #ifndef FWINTERE_H
  53. #include "FWIntere.h"
  54. #endif
  55.  
  56. #ifndef FWBNDSTR_H
  57. #include "FWBndStr.h"
  58. #endif
  59.  
  60. #ifndef FWCFMRES_H
  61. #include "FWCFMRes.h"
  62. #endif
  63.  
  64. #ifndef FWSOMENV_H
  65. #include "FWSOMEnv.h"
  66. #endif
  67.  
  68. #ifndef SLREGION_H
  69. #include "SLRegion.h"
  70. #endif
  71.  
  72. // ----- OpenDoc Includes -----
  73.  
  74. #ifndef SOM_ODFacet_xh
  75. #include <Facet.xh>
  76. #endif
  77.  
  78. #ifndef SOM_ODCanvas_xh
  79. #include <Canvas.xh>
  80. #endif
  81.  
  82. #ifndef SOM_ODTransform_xh
  83. #include <Trnsform.xh>
  84. #endif
  85.  
  86. #ifndef SOM_ODShape_xh
  87. #include <Shape.xh>
  88. #endif
  89.  
  90. //========================================================================================
  91. // Runtime Informations
  92. //========================================================================================
  93.  
  94. #ifdef FW_BUILD_MAC
  95. #pragma segment fwgadgts
  96. #endif
  97.  
  98. //FW_DEFINE_CLASS_M0(FW_CPrivMacControlHelper)
  99.  
  100. #define IS_POPUP_PROCID(id)  (id >= popupMenuProc && id <= popupMenuProc + 15)
  101.  
  102. QDTextUPP FW_CPrivMacGrayishTextProc::fgOldTextProcUPP;
  103.  
  104. //========================================================================================
  105. // CLASS FW_CPrivMacGrayishTextProc
  106. //========================================================================================
  107.  
  108. FW_DEFINE_AUTO(FW_CPrivMacGrayishTextProc)
  109.  
  110. //----------------------------------------------------------------------------------------
  111. // FW_CPrivMacGrayishTextProc::FW_CPrivMacGrayishTextProc
  112. //----------------------------------------------------------------------------------------
  113.  
  114. FW_CPrivMacGrayishTextProc::FW_CPrivMacGrayishTextProc(GrafPtr thePort) :
  115.     fPort(thePort),
  116.     fIsColorPort(((CGrafPtr)(thePort))->portVersion & (0xC000) == 0xC000),
  117.     fQDProcsCreated(false),
  118.     fNewTextProcUPP(NewQDTextProc(TextProcCallback)) 
  119. {
  120.     if (fPort->grafProcs)
  121.     {
  122.         fgOldTextProcUPP = fPort->grafProcs->textProc;
  123.     }
  124.     else
  125.     {
  126.         fgOldTextProcUPP = NULL;
  127.         fQDProcsCreated = true;
  128.         if (fIsColorPort)
  129.         {
  130.             ::SetStdCProcs(&fCQDProcs);
  131.             fPort->grafProcs = (QDProcs*)&fCQDProcs;
  132.         }
  133.         else
  134.         {
  135.             ::SetStdProcs(&fQDProcs);
  136.             fPort->grafProcs = &fQDProcs;
  137.         }
  138.     }
  139.     
  140.     fPort->grafProcs->textProc = fNewTextProcUPP;
  141.     
  142.     FW_END_CONSTRUCTOR
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. // FW_CPrivMacGrayishTextProc::~FW_CPrivMacGrayishTextProc
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_CPrivMacGrayishTextProc::~FW_CPrivMacGrayishTextProc()
  150. {
  151.     FW_START_DESTRUCTOR
  152.     
  153.     if (fQDProcsCreated)
  154.         fPort->grafProcs = NULL;
  155.     else if (fgOldTextProcUPP != NULL)
  156.     {
  157.         fPort->grafProcs->textProc = fgOldTextProcUPP;
  158.         fgOldTextProcUPP = NULL;
  159.     }
  160.     
  161.     if (fNewTextProcUPP)
  162.         DisposeRoutineDescriptor(fNewTextProcUPP);
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. // FW_CPrivMacGrayishTextProc::TextProcCallback
  167. //----------------------------------------------------------------------------------------
  168.  
  169. pascal void FW_CPrivMacGrayishTextProc::TextProcCallback(short byteCount,    
  170.                                                         Ptr textBuf,
  171.                                                         Point numer,
  172.                                                         Point denom)
  173. {
  174.     GrafPtr curPort;
  175.     ::GetPort(&curPort);
  176.     ::RGBColor oldForeColor;
  177.     FW_Boolean modeChanged = false;
  178.  
  179.     if (curPort->txMode == grayishTextOr)
  180.     {
  181.         RGBColor grayColor = FW_CColor(FW_kRGBGray);
  182.         
  183.         ::GetForeColor(&oldForeColor);
  184.         ::RGBForeColor(&grayColor);
  185.         
  186.         ::TextMode(srcOr);
  187.         
  188.         modeChanged = true;
  189.     }
  190.     
  191.     if (FW_CPrivMacGrayishTextProc::fgOldTextProcUPP != NULL)
  192.         CallQDTextProc(FW_CPrivMacGrayishTextProc::fgOldTextProcUPP, byteCount, textBuf, numer, denom);
  193.     else
  194.         StdText(byteCount, textBuf, numer, denom);
  195.     
  196.     
  197.     if (modeChanged)
  198.     {
  199.         ::TextMode(grayishTextOr);
  200.         ::RGBForeColor(&oldForeColor);
  201.     }
  202. }
  203.  
  204. //========================================================================================
  205. // CLASS FW_CPrivMacControlHelper
  206. //========================================================================================
  207.  
  208. //----------------------------------------------------------------------------------------
  209. // FW_CPrivMacControlHelper::FW_CPrivMacControlHelper
  210. //----------------------------------------------------------------------------------------
  211.  
  212. FW_CPrivMacControlHelper::FW_CPrivMacControlHelper(Environment* ev, 
  213.                                                 FW_CNativeControl* control,
  214.                                                 short value, 
  215.                                                 short min, 
  216.                                                 short max, 
  217.                                                 short procID,
  218.                                                 const Str255 label, 
  219.                                                 const FW_CFont& font, 
  220.                                                 long refCon) :
  221.     fControl(control),
  222.     fControlHandle(NULL),
  223.     fControlMargin(0),
  224.     fMacProcID(procID),
  225.     fMacFontID(systemFont),
  226.     fMacFontStyle(normal),
  227.     fMacFontSize(12)
  228. {
  229.     Initialize(ev, value, min, max, label, font, refCon);
  230. }
  231.  
  232. //----------------------------------------------------------------------------------------
  233. // FW_CPrivMacControlHelper::~FW_CPrivMacControlHelper
  234. //----------------------------------------------------------------------------------------
  235.  
  236. FW_CPrivMacControlHelper::~FW_CPrivMacControlHelper()
  237. {
  238.     if (fControlHandle)
  239.         ::DisposeControl(fControlHandle);
  240. }
  241.  
  242. //----------------------------------------------------------------------------------------
  243. // FW_CPrivMacControlHelper::Initialize
  244. //----------------------------------------------------------------------------------------
  245.  
  246. void FW_CPrivMacControlHelper::Initialize(Environment* ev, 
  247.                                         short value, 
  248.                                         short min,         // = menu ID for popups
  249.                                         short max,         // = titleWidth for popups
  250.                                         const Str255 label, 
  251.                                         const FW_CFont& font,
  252.                                         long refCon)
  253. {        
  254.     // Controls are created in the platform window
  255.     FW_CAcquiredODWindow aqODWindow = fControl->GetFrame(ev)->GetWindow(ev)->AcquireODWindow(ev);
  256.     GrafPtr    curWin = aqODWindow->GetPlatformWindow(ev);
  257.     
  258.     FW_CPlatformPoint qdLocation    = fControl->GetLocation(ev).AsPlatformPoint();
  259.     FW_CPlatformPoint qdSize        = fControl->GetSize(ev).AsPlatformPoint();
  260.  
  261.     FW_CPlatformRect rect(qdLocation.h, qdLocation.v,
  262.                           qdLocation.h + qdSize.h, qdLocation.v + qdSize.v);
  263.     
  264.     GrafPtr    oldPort;
  265.     GetPort(&oldPort);
  266.     SetPort(curWin);
  267.     
  268.     RgnHandle clipRgn = ::FW_NewRegion();
  269.     if (clipRgn)
  270.     {
  271.         ::GetClip(clipRgn);
  272.         Rect emptyRect;
  273.         ::SetRect(&emptyRect, 0, 0, 0, 0);
  274.         ::ClipRect(&emptyRect);
  275.     }
  276.  
  277.     fMacFontID = font.MacGetFontID();
  278.     fMacFontStyle = font.MacGetFontStyle();
  279.     fMacFontSize = FW_FixedToInt(font.GetFontSize());
  280.     ::TextFont(fMacFontID);
  281.     ::TextFace(fMacFontStyle);
  282.     ::TextSize(fMacFontSize);
  283.     ::TextMode(srcOr);
  284.  
  285.     if (!font.IsEqual(FW_CFont(FW_kSystemFont))) 
  286.     {
  287.         // Control uses its own font instead of the System Font
  288.         fMacProcID += kControlUsesOwningWindowsFontVariant;
  289.     }
  290.     
  291.     if (IS_POPUP_PROCID(fMacProcID) && max == 0 && label[0] > 0)
  292.     {
  293.         // Compute default title width
  294.         max = ::StringWidth(label) + 5;
  295.     }
  296.     
  297.     FW_CAcquireCFMResourceAccess* resAccess = OpenResFileForPopup(ev); 
  298.     
  299.     fControlHandle = ::NewControl(curWin, &rect, label, false, value, min, max, 
  300.                                                                     fMacProcID, refCon);
  301.     (**fControlHandle).contrlVis = 255;                         
  302.     ::SetControlReference(fControlHandle, (long)this);
  303.  
  304.     if (clipRgn)
  305.     {
  306.         ::SetClip(clipRgn);
  307.         ::FW_DisposeRegion(clipRgn);
  308.     }
  309.  
  310.     if (oldPort != curWin) 
  311.         SetPort(oldPort);
  312.         
  313.     if (resAccess) 
  314.         delete resAccess;
  315. }
  316.  
  317. //----------------------------------------------------------------------------------------
  318. // FW_CPrivMacControlHelper::OpenResFileForPopup
  319. //----------------------------------------------------------------------------------------
  320. // OpenDoc bug or feature?  we must open the part's resource file before any call to
  321. // the control manager because the MENU resource of a popup won't be re-loaded correctly...
  322.  
  323. FW_CAcquireCFMResourceAccess* FW_CPrivMacControlHelper::OpenResFileForPopup(Environment* ev)
  324. {
  325.     FW_CAcquireCFMResourceAccess* resAccess = NULL;
  326.  
  327.     if (IS_POPUP_PROCID(fMacProcID)) 
  328.     {
  329.         resAccess = FW_NEW(FW_CAcquireCFMResourceAccess, (ev));
  330.         FW_ASSERT(resAccess);
  331.     }
  332.     return resAccess;
  333. }    
  334.     
  335. //----------------------------------------------------------------------------------------
  336. // FW_CPrivMacControlHelper::SetBounds
  337. //----------------------------------------------------------------------------------------
  338.  
  339. void FW_CPrivMacControlHelper::SetBounds(const FW_CPlatformRect& controlBounds)
  340. {
  341.     (*fControlHandle)->contrlRect = controlBounds;
  342. }
  343.  
  344. //----------------------------------------------------------------------------------------
  345. // FW_CPrivMacControlHelper::SetValue
  346. //----------------------------------------------------------------------------------------
  347.  
  348. void FW_CPrivMacControlHelper::SetValue(short value, const FW_CPlatformPoint& location,
  349.                                         const FW_CPlatformPoint& size)
  350. {
  351.     // If the value is the same as the current one it may be because we are updating
  352.     // the control in multiple facets (from FW_CNativeControl::PrivSetValue), so we need
  353.     // to force the redraw by changing the old value first
  354.     
  355.     if ((*fControlHandle)->contrlValue == value)
  356.         (*fControlHandle)->contrlValue = (value == 0) ? 1 : 0;
  357.         
  358.     SetupControl(location, size);
  359.     ::SetControlValue(fControlHandle, value);
  360. }
  361.  
  362. //----------------------------------------------------------------------------------------
  363. // FW_CPrivMacControlHelper::SetValue
  364. //----------------------------------------------------------------------------------------
  365.  
  366. void FW_CPrivMacControlHelper::SetValue(short value, FW_Boolean drawNow)
  367. {
  368.     if (drawNow)
  369.         ::SetControlValue(fControlHandle, value);
  370.     else
  371.         (*fControlHandle)->contrlValue = value;
  372. }
  373.  
  374. //----------------------------------------------------------------------------------------
  375. // FW_CPrivMacControlHelper::SetMin
  376. //----------------------------------------------------------------------------------------
  377.  
  378. void FW_CPrivMacControlHelper::SetMin(short min)
  379. {
  380.     // Turn off visibility to avoid unwanted drawing
  381.      short vis = (**fControlHandle).contrlVis;
  382.      (**fControlHandle).contrlVis = 0;
  383.      
  384.     ::SetControlMinimum(fControlHandle, min);
  385.     
  386.      (**fControlHandle).contrlVis = vis;
  387. }
  388.  
  389. //----------------------------------------------------------------------------------------
  390. // FW_CPrivMacControlHelper::SetMax
  391. //----------------------------------------------------------------------------------------
  392.  
  393. void FW_CPrivMacControlHelper::SetMax(short max)
  394. {
  395.     // Turn off visibility to avoid unwanted drawing
  396.      short vis = (**fControlHandle).contrlVis;
  397.      (**fControlHandle).contrlVis = 0;
  398.  
  399.     ::SetControlMaximum(fControlHandle, max);
  400.     
  401.      (**fControlHandle).contrlVis = vis;
  402. }
  403.  
  404. //----------------------------------------------------------------------------------------
  405. // FW_CPrivMacControlHelper::SetText
  406. //----------------------------------------------------------------------------------------
  407.  
  408. void FW_CPrivMacControlHelper::SetText(const FW_CString& text)
  409. {
  410.     Str255 pascalText;
  411.     text.ExportPascal(pascalText);
  412.  
  413.     // Turn off visibility to avoid unwanted drawing
  414.      short vis = (**fControlHandle).contrlVis;
  415.      (**fControlHandle).contrlVis = 0;
  416.  
  417.     ::SetControlTitle(fControlHandle, pascalText);
  418.  
  419.      (**fControlHandle).contrlVis = vis;
  420. }
  421.  
  422. //----------------------------------------------------------------------------------------
  423. // FW_CPrivMacControlHelper::GetText
  424. //----------------------------------------------------------------------------------------
  425.  
  426. void FW_CPrivMacControlHelper::GetText(FW_CString& text) const
  427. {
  428.     Str255 pascalText;
  429.     ::GetControlTitle(fControlHandle, pascalText);
  430.     text.ReplaceAll(pascalText);
  431. }
  432.  
  433. //----------------------------------------------------------------------------------------
  434. // FW_CPrivMacControlHelper::GetFont
  435. //----------------------------------------------------------------------------------------
  436.  
  437. FW_CFont FW_CPrivMacControlHelper::GetFont(Environment* ev) const
  438. {
  439. FW_UNUSED(ev);
  440.     FW_CFont font;
  441.     
  442.     font.MacSetFontID(fMacFontID);
  443.     
  444.     // if the font is the system font, set the size to 12 and
  445.     // ignore the style and size data members
  446.     if (fMacFontID == systemFont)
  447.         font.SetFontSize(FW_IntToFixed(12));
  448.     else
  449.     {
  450.         font.SetFontStyle(FW_CFont::PlatformToODFFontStyle(fMacFontStyle));
  451.         font.SetFontSize(FW_IntToFixed(fMacFontSize));
  452.     }
  453.     
  454.     return font;
  455. }
  456.  
  457. //----------------------------------------------------------------------------------------
  458. // FW_CPrivMacControlHelper::DrawControl
  459. //----------------------------------------------------------------------------------------
  460.  
  461. void FW_CPrivMacControlHelper::DrawControl(Environment* ev, ODFacet* facet)
  462. {
  463.     FW_CAcquiredODWindow aqODWindow = facet->GetFrame(ev)->AcquireWindow(ev);
  464.  
  465.     // All native Mac controls are drawn with Draw1Control except for
  466.     // inactive scroll-bars which are simply empty rectangles
  467.     if (fMacProcID != scrollBarProc || aqODWindow->IsActive(ev)) 
  468.     {
  469.         ::Draw1Control(fControlHandle);
  470.     }
  471.     else
  472.     {
  473.         // Use direct QD calls instead of ODF graphics because the control cannot
  474.         // scale anyway.
  475.         Rect sbRect = (*fControlHandle)->contrlRect;
  476.         ::FrameRect(&sbRect);
  477.         ::InsetRect(&sbRect, 1, 1);
  478.         ::EraseRect(&sbRect);
  479.     }
  480. }
  481.  
  482. //----------------------------------------------------------------------------------------
  483. // FW_CPrivMacControlHelper::Draw
  484. //----------------------------------------------------------------------------------------
  485.  
  486. void FW_CPrivMacControlHelper::Draw(Environment* ev,
  487.                                     ODFacet* facet, 
  488.                                     const FW_CPlatformPoint& location,
  489.                                     const FW_CPlatformPoint& size)
  490. {
  491.     FW_CAcquireCFMResourceAccess* resAccess = OpenResFileForPopup(ev); 
  492.     
  493.     if (facet->GetCanvas(ev)->IsDynamic(ev))
  494.     {
  495.         SetupControl(location, size);
  496.         DrawControl(ev, facet);
  497.      }
  498.      else
  499.      {
  500.          Print(ev, facet, location, size);
  501.      }
  502.      
  503.      if (resAccess)     
  504.          delete resAccess;
  505. }
  506.  
  507. //----------------------------------------------------------------------------------------
  508. // FW_CPrivMacControlHelper::Print
  509. //----------------------------------------------------------------------------------------
  510.  
  511. void FW_CPrivMacControlHelper::Print(Environment* ev, ODFacet* facet, 
  512.                                     const FW_CPlatformPoint& location,
  513.                                     const FW_CPlatformPoint& size)
  514. {    
  515.     GrafPtr     savedPort;
  516.     GrafPtr        usePort = (**fControlHandle).contrlOwner;
  517.  
  518.     ::GetPort(&savedPort);
  519.     ::SetPort(usePort);
  520.     
  521.     SetupControl(FW_CPlatformPoint(0, 0), size);
  522.  
  523.     Rect srcRect;
  524.     srcRect.top = 0;
  525.     srcRect.left = 0;
  526.     srcRect.bottom = size.v;
  527.     srcRect.right = size.h;
  528.     
  529.  
  530.     OpenCPicParams picParams;
  531.     picParams.srcRect = srcRect;
  532.     picParams.hRes = 0x00480000;
  533.     picParams.vRes = 0x00480000;
  534.     picParams.version = -2;
  535.     PicHandle picHandle = ::OpenCPicture(&picParams);
  536.  
  537.     {
  538.         FW_CPrivMacGrayishTextProc grayishTextProc(usePort);
  539.         DrawControl(ev, facet);
  540.     }
  541.     
  542.     ::ClosePicture();
  543.             
  544.      // ----- Set back the port and draw the picture -----
  545.      ::SetPort(savedPort);
  546.      
  547.      ::OffsetRect(&srcRect, location.h, location.v);
  548.      ::DrawPicture(picHandle, &srcRect);
  549.      ::KillPicture(picHandle);
  550.  }
  551.  
  552. //----------------------------------------------------------------------------------------
  553. // FW_CPrivMacControlHelper::Enable
  554. //----------------------------------------------------------------------------------------
  555.  
  556. void FW_CPrivMacControlHelper::Enable(FW_Boolean enabled, const FW_CPlatformPoint& location,
  557.                                     const FW_CPlatformPoint& size)
  558. {
  559.     // Since we may be dealing with multiple facets we need to changing the old hilite 
  560.     // value first to force a correct redraw in each facet.
  561.     
  562.     short hilite = enabled ? 0 : 255;
  563.     
  564.     if (hilite == (*fControlHandle)->contrlHilite)
  565.         (*fControlHandle)->contrlHilite = 255 - hilite;
  566.  
  567.     SetupControl(location, size);
  568.     ::HiliteControl(fControlHandle, hilite); 
  569. }
  570.  
  571. //----------------------------------------------------------------------------------------
  572. // FW_CPrivMacControlHelper::Enable
  573. //----------------------------------------------------------------------------------------
  574.  
  575. void FW_CPrivMacControlHelper::Enable(FW_Boolean enabled)
  576. {
  577.     // Turn off visibility to avoid unwanted drawing
  578.      short vis = (**fControlHandle).contrlVis;
  579.      (**fControlHandle).contrlVis = 0;
  580.     
  581.     ::HiliteControl(fControlHandle, enabled ? 0 : 255);
  582.  
  583.      (**fControlHandle).contrlVis = vis;
  584. }
  585.  
  586. //----------------------------------------------------------------------------------------
  587. // FW_CPrivMacControlHelper::Show
  588. //----------------------------------------------------------------------------------------
  589. // This version of Show can be used for immediate drawing (like scrollbar activation)
  590.  
  591. void FW_CPrivMacControlHelper::Show(const FW_CPlatformPoint& location,
  592.                                     const FW_CPlatformPoint& size)
  593. {
  594.     // We need to reset the visibility to 0 before calling ::ShowControl to force the
  595.     // control manager to show it again. For instance a scrollbar activation may
  596.     // occur across multiple facets and this method will be called for each facet!
  597.      (**fControlHandle).contrlVis = 0;
  598.  
  599.     SetupControl(location, size);
  600.     ::ShowControl(fControlHandle);
  601. }
  602.  
  603. //----------------------------------------------------------------------------------------
  604. // FW_CPrivMacControlHelper::Show
  605. //----------------------------------------------------------------------------------------
  606.  
  607. void FW_CPrivMacControlHelper::Show()
  608. {
  609.     // Only change visibility flag.  View should be invalidated 
  610.      (**fControlHandle).contrlVis = 255;
  611. }
  612.  
  613. //----------------------------------------------------------------------------------------
  614. // FW_CPrivMacControlHelper::Hide
  615. //----------------------------------------------------------------------------------------
  616.  
  617. void FW_CPrivMacControlHelper::Hide()  
  618. {
  619.     // Only change visibility flag.  View should be invalidated 
  620.      (**fControlHandle).contrlVis = 0;
  621. }
  622.  
  623. //----------------------------------------------------------------------------------------
  624. // FW_CPrivMacControlHelper::Hide
  625. //----------------------------------------------------------------------------------------
  626.  
  627. void FW_CPrivMacControlHelper::SimulateButtonPressed(const FW_CPlatformPoint& location,
  628.                                     const FW_CPlatformPoint& size)
  629. {
  630.     SetupControl(location, size);
  631.     long ticks;
  632.     ::HiliteControl(fControlHandle, kControlButtonPart);
  633.     ::Delay(10, &ticks);
  634.     ::HiliteControl(fControlHandle, 0);
  635. }
  636.  
  637. //----------------------------------------------------------------------------------------
  638. // FW_CPrivMacControlHelper::MouseDown
  639. //----------------------------------------------------------------------------------------
  640.  
  641. FW_Boolean FW_CPrivMacControlHelper::MouseDown(Environment* ev, const FW_CViewContext& vc,
  642.                                                     const FW_CPlatformPoint& whereMouse)
  643. {
  644.     FW_CPlatformPoint controlLocation = vc.LogicalToDevice(FW_kZeroPoint);
  645.     FW_CPlatformPoint controlSize = GetControl()->GetSize(ev).AsPlatformPoint();
  646.  
  647.     SetupControl(controlLocation, controlSize);
  648.  
  649.     FW_CAcquireCFMResourceAccess* resAccess = OpenResFileForPopup(ev); 
  650.     
  651.     // [LSD] hack for popups who don't seem to respond to TestControl normally...
  652.     short partCode = ::TestControl(fControlHandle, whereMouse);
  653.     if (IS_POPUP_PROCID(fMacProcID))
  654.     {
  655.         partCode = kControlMenuPart;
  656.         ::PenSize(0, 0);
  657.         ::Draw1Control(fControlHandle);    
  658.         ::PenNormal();
  659.     }
  660.         
  661.     FW_Boolean mouseHandled = PartCodeSwitch(ev, vc, whereMouse, partCode);
  662.     
  663.     if (resAccess) 
  664.         delete resAccess;
  665.     
  666.     return mouseHandled;
  667. }
  668.  
  669. //----------------------------------------------------------------------------------------
  670. // FW_CPrivMacControlHelper::PartCodeSwitch
  671. //----------------------------------------------------------------------------------------
  672.  
  673. FW_Boolean FW_CPrivMacControlHelper::PartCodeSwitch(Environment* ev, const FW_CViewContext& vc, const FW_CPlatformPoint& whereMouse, short partCode)
  674. {
  675.     FW_Boolean mouseHandled = TRUE;
  676.     ODFacet* facet = vc.GetFacet();
  677.     
  678.     switch (partCode)
  679.     {    
  680.         case kControlButtonPart:
  681.         case kControlCheckBoxPart:  // = kControlRadioButtonPart: 
  682.             {
  683.                 if (::TrackControl(fControlHandle, whereMouse, NULL)) 
  684.                 {            
  685.                     GetControl()->ControlClicked(ev, GetValue(), facet);
  686.                 }
  687.             }    
  688.             break;
  689.             
  690.         case kControlIndicatorPart:
  691.         case kControlMenuPart:
  692.             {
  693.                 short before = GetValue();
  694.                 ::TrackControl(fControlHandle, whereMouse, (ControlActionUPP) (-1));
  695.                 short after = GetValue();
  696.                 
  697.                 if (after != before)
  698.                 {
  699.                     if (partCode == kControlIndicatorPart)
  700.                         after = after - before;    // use a delta for scroll bars
  701.                         
  702.                     GetControl()->ControlClicked(ev, after, facet);
  703.                 }
  704.                 
  705.             }
  706.             break;
  707.         
  708.         default:
  709.             mouseHandled = FALSE;
  710.     }
  711.     
  712.     return mouseHandled;
  713. }    
  714.  
  715. //----------------------------------------------------------------------------------------
  716. // FW_CPrivMacControlHelper::SetupControl
  717. //----------------------------------------------------------------------------------------
  718.  
  719. void FW_CPrivMacControlHelper::SetupControl(const FW_CPlatformPoint& location,
  720.                                          const FW_CPlatformPoint& size)
  721. {
  722.     // Set control coordinates
  723.     (*fControlHandle)->contrlRect.top = location.v + fControlMargin;
  724.     (*fControlHandle)->contrlRect.left = location.h + fControlMargin;
  725.     (*fControlHandle)->contrlRect.bottom = location.v + size.v - fControlMargin;
  726.     (*fControlHandle)->contrlRect.right = location.h + size.h - fControlMargin;
  727.     
  728.     ::PenNormal();
  729.  
  730.     // Set port's font if control doesn't use the default system font
  731.     if (fMacFontID != systemFont) 
  732.     {
  733.         ::TextFont(fMacFontID);
  734.         ::TextFace(fMacFontStyle);
  735.         ::TextSize(fMacFontSize);
  736.         ::TextMode(srcOr);    
  737.     }
  738. }
  739.  
  740. //========================================================================================
  741. //    CLASS FW_CPrivMacScrollBarControlHelper
  742. //========================================================================================
  743.  
  744. //----------------------------------------------------------------------------------------
  745. // FW_CPrivMacScrollBarControlHelper::FW_CPrivMacScrollBarControlHelper
  746. //----------------------------------------------------------------------------------------
  747.  
  748. FW_CPrivMacScrollBarControlHelper::FW_CPrivMacScrollBarControlHelper(Environment* ev, 
  749.                                                                     FW_CNativeControl* control,
  750.                                                                     short value, 
  751.                                                                     short min, 
  752.                                                                     short max,
  753.                                                                     long refCon) :
  754.     FW_CPrivMacControlHelper(ev, control, value, min, max, scrollBarProc, "\p", FW_kSystemFont, refCon),
  755.     fFacet(0)
  756. {
  757. }
  758.  
  759. //----------------------------------------------------------------------------------------
  760. // FW_CPrivMacScrollBarControlHelper::~FW_CPrivMacScrollBarControlHelper
  761. //----------------------------------------------------------------------------------------
  762.  
  763. FW_CPrivMacScrollBarControlHelper::~FW_CPrivMacScrollBarControlHelper()
  764. {
  765. }
  766.  
  767. //----------------------------------------------------------------------------------------
  768. // FW_CPrivMacScrollBarControlHelper::PartCodeSwitch
  769. //----------------------------------------------------------------------------------------
  770.  
  771. FW_Boolean FW_CPrivMacScrollBarControlHelper::PartCodeSwitch(Environment* ev, 
  772.                                                             const FW_CViewContext& vc, 
  773.                                                             const FW_CPlatformPoint& whereMouse, 
  774.                                                             short partCode)
  775. {
  776.     FW_Boolean mouseHandled = FW_CPrivMacControlHelper::PartCodeSwitch(ev, vc, whereMouse, partCode);
  777.     
  778.     if (!mouseHandled)
  779.     {
  780.         mouseHandled = TRUE;
  781.         fFacet = vc.GetFacet();
  782.         
  783.         switch (partCode)
  784.         {    
  785.             case kControlDownButtonPart:
  786.             case kControlUpButtonPart:
  787.             case kControlPageDownPart:
  788.             case kControlPageUpPart:
  789.                 {
  790.                     ControlActionUPP actionProc = NewControlActionProc(&CallActionProc);
  791.                     
  792.                     GrafPtr macPort;
  793.                     ::GetPort(&macPort);
  794.                     
  795.                     ::TrackControl(fControlHandle, whereMouse, actionProc);
  796.                     DisposeRoutineDescriptor((UniversalProcPtr) actionProc);
  797.                 }
  798.                 break;
  799.                         
  800.             default:
  801.                 mouseHandled = FALSE;
  802.         }
  803.     }
  804.     
  805.     
  806.     return mouseHandled;
  807. }    
  808.  
  809. //----------------------------------------------------------------------------------------
  810. // FW_CPrivMacScrollBarControlHelper::CallActionProc
  811. //----------------------------------------------------------------------------------------
  812.  
  813. pascal void FW_CPrivMacScrollBarControlHelper::CallActionProc(ControlHandle controlHandle,
  814.                                                   short partCode)
  815. {
  816.     FW_CPrivMacScrollBarControlHelper *controlHelper = (FW_CPrivMacScrollBarControlHelper*)::GetControlReference(controlHandle);
  817.     
  818.     controlHelper->ActionProc(partCode);
  819. }
  820.  
  821. //----------------------------------------------------------------------------------------
  822. // FW_CPrivMacScrollBarControlHelper::ActionProc
  823. //----------------------------------------------------------------------------------------
  824.  
  825. void FW_CPrivMacScrollBarControlHelper::ActionProc(short partCode)
  826. {
  827.     FW_SOMEnvironment ev;
  828.     
  829.     FW_CScrollBar* scrollBar = FW_DYNAMIC_CAST(FW_CScrollBar, GetControl());
  830.     FW_ASSERT(scrollBar);
  831.     FW_ASSERT(fFacet);
  832.  
  833.     FW_Fixed changeBy = FW_kFixed0;
  834.     
  835.     switch (partCode)
  836.     {
  837.         case kControlDownButtonPart:
  838.             changeBy = scrollBar->GetMinorScrollUnits(ev);
  839.             break;
  840.             
  841.         case kControlUpButtonPart:
  842.             changeBy = -scrollBar->GetMinorScrollUnits(ev);
  843.             break;
  844.             
  845.         case kControlPageDownPart:
  846.             changeBy = scrollBar->GetMajorScrollUnits(ev);
  847.             break;
  848.             
  849.         case kControlPageUpPart:
  850.             changeBy = -scrollBar->GetMajorScrollUnits(ev);
  851.             break;
  852.     };
  853.  
  854.     short before = GetValue();
  855.     short after = before + FW_FixedToInt(changeBy);
  856.     
  857.     short min = GetMin();
  858.     short max = GetMax();
  859.     if (after < min)
  860.         after = min;
  861.     else if (after > max)
  862.         after = max;
  863.  
  864.     if (after != before)
  865.     {        
  866.         // [LSD] we need to save & restore the contrlRect of the original facet because
  867.         // multiple facets will change it and TrackControl returns with wrong udpate.
  868.         Rect savedRect =  (*fControlHandle)->contrlRect;
  869.         
  870.         GetControl()->ControlClicked(ev, after - before, fFacet);
  871.         
  872.         (*fControlHandle)->contrlRect = savedRect;
  873.     }
  874. }
  875.  
  876.  
  877. #endif
  878.